﻿using System.Text;

namespace OpenCompiler.Scanning.Scanners
{
	public unsafe class StringLiteralScanner : TokenScanner
	{
		private const string StringLiteralCharacters = "\"'";
		private readonly char[] _stringLiteralCharacters;

		public StringLiteralScanner()
		{
			this._stringLiteralCharacters = Encoding.Default.GetChars(Encoding.Default.GetBytes(StringLiteralCharacters));
		}


		public override bool IsToken(char* stringPointer, int remainingCharacters)
		{
			return TokenHelper.IsCharacter(stringPointer[0], this._stringLiteralCharacters);
		}

		public override object GetToken(ref char* stringPointer, int remainingCharacters)
		{
			var endEnclosure = stringPointer[0];
			return TokenHelper.GetTokenFromEnclosure(ref stringPointer, ref remainingCharacters, endEnclosure);
		}
	}
}
